package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.MessageBean;
import com.xianbeiying.app.ckgl.util.DataUtil;

/**
 * 我的消息数据适配
 */
public class MyMessageListdapter extends BaseAdapter{

private Context context;
    private MessageBean messageBean;

public MyMessageListdapter(Context context,MessageBean messageBean) {
        this.context = context;
        this.messageBean=messageBean;
        }

    @Override
    public int getCount() {
        return messageBean.getMESSAGE().size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_my_message, parent, false);
            holder = new ViewHolder();
            holder.view_message_line2=(View) convertView.findViewById(R.id.view_message_line2);
            holder.view_message_line1=(View) convertView.findViewById(R.id.view_message_line1);
            holder.tv_message_date=(TextView) convertView.findViewById(R.id.tv_message_date);
            holder.tv_message_content=(TextView) convertView.findViewById(R.id.tv_message_content);
            holder.tv_message_title=(TextView) convertView.findViewById(R.id.tv_message_title);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.view_message_line2.setVisibility(View.VISIBLE);
        if((position+1)==messageBean.getMESSAGE().size()){
            holder.view_message_line2.setVisibility(View.GONE);
        }
//        else{
            holder.tv_message_content.setText(messageBean.getMESSAGE().get(position).getContent());
            holder.tv_message_title.setText(messageBean.getMESSAGE().get(position).getTitle());
            holder.tv_message_date.setText(DataUtil.paserTime(messageBean.getMESSAGE().get(position).getMessTime() + "", "yyyy-MM-dd HH:mm"));
//        }
        return convertView;
    }
    private class ViewHolder{
        View view_message_line1,view_message_line2;
        TextView tv_message_content;
        TextView tv_message_date;
        TextView tv_message_title;
    }
}
